package santiago.server;

import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Set;
import santiago.codebase.IClient;
import santiago.codebase.IServer;
import santiago.domain.CardinalPoint;
import santiago.domain.DifficultyLevel;
import santiago.domain.Game;
import santiago.domain.Player;
import santiago.exception.AlreadyInGameException;
import santiago.exception.ExistingItemException;
import santiago.exception.InvalidAmountException;
import santiago.exception.MaximalPlayerCountReachedException;
import santiago.exception.NoSuchGameException;
import santiago.exception.NotEnoughCashException;
import santiago.exception.NotEnoughPlayerException;

public class RMIServer implements IServer {

    @Override
    public synchronized void connect(String Login, IClient Client) throws RemoteException, ExistingItemException {
        Server.addClient(Login, Client);
    }

    @Override
    public void disconnect(String Login) throws RemoteException {
        Server.removeClient(Login);
    }

    @Override
    public synchronized void createGame(String GameName, int PlayerNbr, DifficultyLevel Level, boolean DisplayCash, boolean PalmTree) throws RemoteException, ExistingItemException {
        Server.createGame(GameName, PlayerNbr, Level, DisplayCash, PalmTree);
    }

    @Override
    public synchronized void joinGame(String GameName, String Login) throws RemoteException, ExistingItemException, MaximalPlayerCountReachedException, AlreadyInGameException, NoSuchGameException, NotEnoughPlayerException {
        Server.joinGame(GameName, Login);
    }

    @Override
    public void leaveGame(String Login, String GameName) throws RemoteException, NoSuchGameException {
        Server.leaveGame(Login, GameName);
    }

    @Override
    public void sendMessage(String Login, String Message) throws RemoteException {
        Server.sendMessage(Login, Message);
    }

    @Override
    public void bid(String Login, int Amount) throws RemoteException, InvalidAmountException, NotEnoughCashException {
        Server.bid(Login, Amount);
    }

    @Override
    public void placePlantation(String Login, int NodeIndex, int PlantationIndex, CardinalPoint Location) throws RemoteException {
        Server.placePlantation(Login, NodeIndex, PlantationIndex, Location);
    }

    @Override
    public Set<Game> getGames() throws RemoteException {
        return Server.getAvailableGames();
    }

    @Override
    public Player getPlayer(String Login) throws RemoteException {
        return Server.getPlayer(Login);
    }

    @Override
    public Collection<Player> getPlayers(String GameName) throws RemoteException, NoSuchGameException {
        return Server.getGamePlayers(GameName);
    }

    @Override
    public Game getGame(String GameName) throws RemoteException {
        return Server.getGame(GameName);
    }
}
